<html>
<head><meta charset="utf-8"><title>Need help on #1377 · clippy · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/index.html">clippy</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Need.20help.20on.20.231377.html">Need help on #1377</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="212878200"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Need%20help%20on%20%231377/near/212878200" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> dvermd <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Need.20help.20on.20.231377.html#212878200">(Oct 09 2020 at 21:34)</a>:</h4>
<p>Hi, <br>
I'm new to clippy dev and trying to implement the lint defined in <a href="https://github.com/rust-lang/rust-clippy/issues/1377">https://github.com/rust-lang/rust-clippy/issues/1377</a>.</p>
<p>I parsed the <code>expr</code> as <code>AddrOf</code> and then as <code>Path</code> but can't find a way to check for <code>Option</code> and/or extract its <code>T</code>. <br>
I didn't manage to find another lint to get inspiration on that. Do you have any pointer to such an example ?</p>
<p>Something else : I'm blindly stuck as I can't debug my lint to understand where it doesn't trigger. <br>
Can you give a hint on how to debug lints ? </p>
<p>I hope that's the right place to ask for help.</p>



<a name="212883242"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Need%20help%20on%20%231377/near/212883242" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> montrivo <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Need.20help.20on.20.231377.html#212883242">(Oct 09 2020 at 22:43)</a>:</h4>
<p>Are you looking at <code>ExprKind::AddrOf</code>? I understand the issue as applying to types in function signatures and variable annotations instead. <br>
Did you give a look at <code>TyKind::Adt</code>?<br>
As for debugging, I usually put <code>dbg!(expr);</code> statements and run the ui tests. You can also run clippy on an isolated snippet with <code>env CLIPPY_TESTS=true cargo run --bin clippy-driver -- -L ./target/debug input.rs</code>. See <a href="https://github.com/rust-lang/rust-clippy/blob/master/doc/adding_lints.md#testing-manually">https://github.com/rust-lang/rust-clippy/blob/master/doc/adding_lints.md#testing-manually</a> .</p>



<a name="212883889"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Need%20help%20on%20%231377/near/212883889" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> montrivo <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Need.20help.20on.20.231377.html#212883889">(Oct 09 2020 at 22:54)</a>:</h4>
<p>TyKind doc link: <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/enum.TyKind.html">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/enum.TyKind.html</a></p>



<a name="212890957"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Need%20help%20on%20%231377/near/212890957" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eduardo Broto <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Need.20help.20on.20.231377.html#212890957">(Oct 10 2020 at 00:36)</a>:</h4>
<p>I also understand it like <span class="user-mention" data-user-id="295035">@montrivo</span> says. I think it would make sense to lint in a couple places: locals, statics/consts, associated types, type alias, function/method parameter/return, ADT definitions (struct/tuple struct fields, enum variants).</p>
<p>Once you have a <code>Ty</code>, you can check if it's an <code>Option</code> with <code>utils::is_type_diagnostic_item(cx, ty, sym!(option_type))</code>.<br>
To retrieve the <code>T</code> in <code>Option&lt;T&gt;</code> you can do <code>option_ty.walk().nth(1).unwrap().expect_ty()</code>.</p>
<p>At any point, do not hesitate to open a PR, we can try to help.</p>



<a name="212901912"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Need%20help%20on%20%231377/near/212901912" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> dvermd <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Need.20help.20on.20.231377.html#212901912">(Oct 10 2020 at 06:27)</a>:</h4>
<p>Thanks for these pointers, I'll rework the lint with those</p>



<a name="213084873"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Need%20help%20on%20%231377/near/213084873" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> dvermd <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Need.20help.20on.20.231377.html#213084873">(Oct 12 2020 at 20:47)</a>:</h4>
<p>I was quite happy with my progress but I re-run <a href="http://setup-toolchain.sh">setup-toolchain.sh</a> and I'm now stuck with</p>
<div class="codehilite"><pre><span></span><code>error[E0603]: function `run_compiler` is private
   --&gt; src/driver.rs:360:34
    |
360 |             return rustc_driver::run_compiler(&amp;args, &amp;mut DefaultCallbacks, None, None, None);
    |                                  ^^^^^^^^^^^^ private function
    |
note: the function `run_compiler` is defined here

error[E0603]: function `run_compiler` is private
   --&gt; src/driver.rs:423:23
    |
423 |         rustc_driver::run_compiler(&amp;args, callbacks, None, None, None)
    |                       ^^^^^^^^^^^^ private function
    |
note: the function `run_compiler` is defined here
</code></pre></div>


<p>I read the docs and that understands that this happens. Is there a way to set a "working" version of the nightly toolchain to continue working on this issue ?</p>



<a name="213084974"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Need%20help%20on%20%231377/near/213084974" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eduardo Broto <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Need.20help.20on.20.231377.html#213084974">(Oct 12 2020 at 20:48)</a>:</h4>
<p>I believe you need a rebase of your branch on top of the current master</p>



<a name="213213719"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Need%20help%20on%20%231377/near/213213719" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> dvermd <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Need.20help.20on.20.231377.html#213213719">(Oct 13 2020 at 20:40)</a>:</h4>
<p>I pushed some commits that break the tests with </p>
<div class="codehilite"><pre><span></span><code>error: since &amp; implements Copy trait, &amp;Option&lt;&amp;T&gt; can be simplifyied into Option&lt;&amp;T&gt;
  --&gt; $DIR/option_if_let_else.rs:23:21
   |
LL | fn unop_bad(string: &amp;Option&lt;&amp;str&gt;, mut num: Option&lt;i32&gt;) {
   |                     ^^^^^^^^^^^^^ help: try: `Option&lt;&amp;str&gt;`
   |
   = note: `-D clippy::ref-option-ref` implied by `-D warnings`
</code></pre></div>


<p>I should have run <code>cargo uitest</code> instead of just <code>TESTNAME=ref_option_ref cargo uitest</code> before pushing.</p>
<p>Now, how would I fix this ? I think of either changing the <code>option_if_let_else.rs</code> method signature or disabling the <code>ref-option-ref</code> lint for <code>option_if_let_else</code> ?</p>



<a name="213214147"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Need%20help%20on%20%231377/near/213214147" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eduardo Broto <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Need.20help.20on.20.231377.html#213214147">(Oct 13 2020 at 20:44)</a>:</h4>
<p>The latter, allowing the new lint should suffice</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>